/**
 * Created by Administrator on 15-9-28.
 */

window.onload=function(){
    getLocation_denglu();
//    var geolocation = new BMap.Geolocation();
//    geolocation.getCurrentPosition(function(r) {
//        var storage = window.localStorage;
//        storage.setItem("lng", r.point.lng);
//        storage.setItem("lat", r.point.lat);
//    });
    var url=getUrl();
    $(".log-denglu").on("click",function(){

        var phonenum=$("#phonenum").val();
        var password=$("#password").val();

        if(phonenum==""){
            showToast("手机号码不能为空~");
            return;
        }

        if(password=="")
        {
            showToast("密码不能为空~");
            return;
        }
        if(phonenum.length!=11)
        {
            showToast("手机号格式不对~");
            return;
        }
        $.jsonp({
            url: 'http://'+url+'/api/user/user_login',
            data: {telphone:phonenum,password:password},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {

                if(data.succ==true){
                    $.jsonp({
                        url: 'http://'+url+'/api/user/main',
                        data: {userId:data.userId},
                        callbackParameter: "callback",
                        success: function (data, textStatus, xOptions) {
                            try{
                               var storage = window.localStorage;
                               storage.setItem("userid",data.id);
                            storage.setItem("phonenum",phonenum);
                            
                            easeMobLogin();
                            
                               jumpSendLoginData(phonenum,password);

                               var jumpurl = storage.getItem("jumpurl");

                               location.href=jumpurl;
                               //alert("user_id==="+storage.getItem("userid"));}catch(e){
                               //alert(e);
                            }catch(e){
                                //alert(e);
                                location.href="index.html";
                            }
                            //location.href="index.html";
                        },
                        error: function (xOptions,textStatus) {
                        }
                    });


                }else{
                    showToast("手机号或密码错，请重新登录~");
                }
            },
            error: function (xOptions,textStatus) {
            }
        });



    });
}

function setLocation_denglu(lat,lng){
    var storage = window.localStorage;
    storage.setItem("lng", lng);
    storage.setItem("lat", lat);
}

